#include <limits.h>  // INT_MIN,INT_MAX
#include <math.h>    // abs,pow

#include <iostream>       // cout,cin
#include <string>         // string
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set

using namespace std;

class Solution {
   public:
    int singleNumber(vector<int>& nums) {
        unordered_set<int> set1 = {};
        unordered_set<int> set2 = {};
        for (int num : nums) {
            if (set1.find(num) != set1.end()) {
                set1.erase(num);
                set2.insert(num);
            } else if (set2.find(num) == set2.end()) {
                set1.insert(num);
            }
        }
        return *set1.begin();
    }
};